module teapo.app.tests {
export class TestCase {
state = ko.observable(TestCase.State.NotStarted);
runtime = ko.observable<number>(null);
failure = ko.observable<Error>(null);
private _started = -1;
constructor(public name: string,
private _test: Function) {
}
start() {if (this.state() !== TestCase.State.NotStarted)
throw new Error('Test case already started (' + TestCase.State[this.state()] + ').');
this.state(TestCase.State.Running);
this.runtime(0);
this._started = 0;
var failed = false;
var failure: Error = null;
try {var test = this._test;
test();}
catch (error) {
failed = true;
failure = error;
}
var now = Date.now();
this.runtime(now - this._started);
if (failed) {
this.failure(failure);
this.state(TestCase.State.Failed);
}
else {
this.state(TestCase.State.Succeeded);
}
}
}
export module TestCase {
export enum State {
NotStarted, Running, Succeeded, Failed}
}
}